﻿using Apps.Common;
using Apps.Models;
using Apps.Models.S;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.BLL.S
{
    public partial class S_COLLECTSAMPLEBLL
    {
        public DBContainer db = new DBContainer();

        public List<V_S_COLLECTSAMPLE_RC> GetList_RC(ref GridPager pager, string batch, string startdate, string enddate)
        {
            IQueryable<V_S_COLLECTSAMPLE_RC> queryData = this.db.V_S_COLLECTSAMPLE_RC.AsQueryable();
            if (!string.IsNullOrEmpty(batch))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(batch));
            }
            if (!string.IsNullOrEmpty(startdate))
            {
                DateTime dStartDate = DateTime.ParseExact(startdate, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.RECEIVE_TIME >= dStartDate);
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                DateTime dEndDate = DateTime.ParseExact(enddate, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.RECEIVE_TIME < dEndDate);
            }

            //var data = from m1 in queryData
            //           join m2 in db.SysUser on m1.R_USER_ID equals m2.Id
            //           join m3 in db.SysUser on m1.S_USER_ID equals m3.Id
            //           select new S_COLLECTSAMPLEModel()
            //           {
            //               BATCH_CODE = m1.BATCH_CODE,
            //               SAMPLE_CODE = m1.SAMPLE_CODE,
            //               RFID = m1.RFID,
            //               COLLECT_CODE = m1.COLLECT_CODE,
            //               R_USER_NAME = m2.TrueName,
            //               RECEIVE_TIME = m1.RECEIVE_TIME,
            //               S_USER_NAME = m3.TrueName,
            //               BLENDED = m1.BLENDED,
            //               MADE = m1.MADE,
            //               WEIGHT = m1.WEIGHT,
            //               WEIGHT_STATUS = m1.WEIGHT_STATUS,
            //               SAMPLE_TYPE = m1.SAMPLE_TYPE
            //           };

            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return queryData.ToList();
            //retval.ForEach(p => p.RECEIVE_DATE = (p.RECEIVE_TIME.HasValue ? p.RECEIVE_TIME.Value.ToString("yyyy-MM-dd") : ""));
            //return retval;
        }

        public List<V_S_COLLECTSAMPLE_RL> GetList_RL(ref GridPager pager, string batch, string startdate, string enddate)
        {
            IQueryable<V_S_COLLECTSAMPLE_RL> queryData = this.db.V_S_COLLECTSAMPLE_RL.AsQueryable();
            if (!string.IsNullOrEmpty(batch))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(batch));
            }
            if (!string.IsNullOrEmpty(startdate))
            {
                DateTime dStartDate = DateTime.ParseExact(startdate, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.RECEIVE_TIME >= dStartDate);
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                DateTime dEndDate = DateTime.ParseExact(enddate, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.RECEIVE_TIME < dEndDate);
            }

            //var data = from m1 in queryData
            //           join m2 in db.SysUser on m1.R_USER_ID equals m2.Id
            //           join m3 in db.SysUser on m1.S_USER_ID equals m3.Id
            //           select new S_COLLECTSAMPLEModel()
            //           {
            //               BATCH_CODE = m1.BATCH_CODE,
            //               SAMPLE_CODE = m1.SAMPLE_CODE,
            //               RFID = m1.RFID,
            //               COLLECT_CODE = m1.COLLECT_CODE,
            //               R_USER_NAME = m2.TrueName,
            //               RECEIVE_TIME = m1.RECEIVE_TIME,
            //               S_USER_NAME = m3.TrueName,
            //               BLENDED = m1.BLENDED,
            //               MADE = m1.MADE,
            //               WEIGHT = m1.WEIGHT,
            //               WEIGHT_STATUS = m1.WEIGHT_STATUS,
            //               SAMPLE_TYPE = m1.SAMPLE_TYPE
            //           };

            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return queryData.ToList();
            //retval.ForEach(p => p.RECEIVE_DATE = (p.RECEIVE_TIME.HasValue ? p.RECEIVE_TIME.Value.ToString("yyyy-MM-dd") : ""));
            //return retval;
        }
    }
}
